/**
 * 
 */
package mdb.com.vn.persist;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import mdb.com.vn.model.Card;
import mdb.com.vn.utils.DateUtils;

/**
 * @author tu.dod
 *
 */
@Repository("cardDAO")
public class CardDAOImpl extends AbstractHibernateDAOImpl<Card, Integer> implements CardDAO,Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected Class<Card> getDomainClass() {
		// TODO Auto-generated method stub
		return Card.class;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Card> findByStatus(String status) {
		// TODO Auto-generated method stub
		return getSession().getNamedQuery("Card.findByStatus").setString("status", status).list();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Card> findByStatus(String status, Date processDate) {
		// TODO Auto-generated method stub
		return getSession().getNamedQuery("Card.findByStatusDate").setString("status", status).setDate("processDate", processDate).list();
	}

	@Override
	public void addCardLuckyDrawG2ByScript(String createdBy, Date processDate) {
		try {
			String strDate = DateUtils.format(processDate, "dd-MMM-yyyy");
			Query query = getSession().createSQLQuery("CALL mdbpks_bpro_services.pr_generate_lkd_card_period(:processDate,:createdBy)");
			query.setParameter("createdBy", createdBy);
			query.setParameter("processDate", strDate);
			query.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
